<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-仓库管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
		<div class="page_header"><a>仓库管理</a></div>
			<div class="search">
			<form action="<%=basePath %>warehouse/listWarehouse.do" method="post" class="form">
				<input type="hidden" name="currentPage" value="1" class="form-control">
				<p>
						<label>仓库代码</label>
						<input type="text" name="warehousecode" value="${warehousePage.warehousecode }" class="form-control"></input>
						<label>仓库名称</label>
						<input type="text" name="warehousename" value="${warehousePage.warehousename }" class="form-control"></input>
						<label>状态</label>
						<select name="status" class="form-control select">
							<option value="">全部</option>
							<option value="可用" ${warehousePage.status=="可用"?"selected":"" }>可用</option>
							<option value="不可用" ${warehousePage.status=="不可用"?"selected":"" }>不可用</option>
						</select>
						<input type="submit" value="查询"  class="btn btn1"></input>		
						<c:if test="${isAdd }">
							<input type="button" value="新增" onclick="addWarehouse();"  class="btn btn1"></input>
						</c:if>
						<input type="button" value="编辑" onclick="toEditWarehouse();"  class="btn btn1"></input>
						<c:if test="${isDelete }">
							<input type="button" value="删除" onclick="toDeleteWarehouse();" class="btn btn_danger"></input>
						</c:if>
				</p>
			</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:140px;">操作</th>
							<th>仓库代码</th>
							<th>仓库名称</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>创建人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${warehouseList}" var="warehouse" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateWarehouse" value="${warehouse.warehousemanagementid }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn1" onclick="editWarehouse(${warehouse.warehousemanagementid });">编辑</a>
									<c:if test="${isDelete }">
										<a class="btn btn-xs btn_danger" onclick="confirmDeleteWarehouse(${warehouse.warehousemanagementid });">删除</a>
									</c:if>
								</td>
								<td>${warehouse.warehousecode }</td>
								<td>${warehouse.warehousename }</td>
								<td>${warehouse.status }</td>
								<td><fmt:formatDate value="${warehouse.createdate }"
										type="date" /></td>
								<td>${warehouse.createpersonname }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<%-- <table class="pageTable">
				<tr>
					<td style="width:300px">
						<div>
							<h6>
								共<strong style="color: #b93d00">${warehousePage.rows }</strong>条记录
								&nbsp;当前<strong style="color: #b93d00">${warehousePage.currentPage }/${warehousePage.totalPage }</strong>页&nbsp;
								<select name="pageSize" style="width:100px;" onchange="pageSizeChange(this)">
									<option <c:if test="${warehousePage.pageSize==10 }">selected</c:if> value="10">10</option>
									<option <c:if test="${warehousePage.pageSize==20 }">selected</c:if> value="20">20</option>
									<option <c:if test="${warehousePage.pageSize==50 }">selected</c:if> value="50">50</option>
								</select>
							</h6>
						</div>
					</td>
					<td>
						<div>
							<ul class="pagination">
								<li><a
									href="<%=basePath %>warehouse/listWarehouse.do?currentPage=1">首页</a></li>
								<li><a
									href="<%=basePath %>warehouse/listWarehouse.do?currentPage=${warehousePage.currentPage-1 }">上一页</a></li>

								<c:forEach begin="${warehousePage.currentPage-4>0?warehousePage.currentPage-4:1 }" end="${warehousePage.currentPage+4 }" step="1" var="i">
									<c:if test="${i>0 && i<=warehousePage.totalPage }">
										<li><a
											href="<%=basePath %>warehouse/listWarehouse.do?currentPage=${i }"
											${i==warehousePage.currentPage?"style='color: red'":"" }>${i}</a></li>
									</c:if>
								</c:forEach>
								<li><a
									href="<%=basePath %>warehouse/listWarehouse.do?currentPage=${warehousePage.currentPage+1 }">下一页</a></li>
								<li><a
									href="<%=basePath %>warehouse/listWarehouse.do?currentPage=${warehousePage.totalPage }">尾页</a></li>
							</ul>
						</div>
					</td>
					<td style="width:300px">
						<div>
							<form class="navbar-form" role="search"
								action="<%=basePath %>warehouse/listWarehouse.do"
								method="post">
								<input type="text" class="form-control" name="currentPage"
									onkeyup="this.value=this.value.replace(/\D/g,'')"
									onchange="this.value=this.value.replace(/\D/g,'')" />
								<button type="submit" class="btn btn-default">跳转</button>
							</form>
						</div>
					</td>
				</tr>
			</table> --%>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		
		<jsp:include page="/jsp/basicData/warehouseManage/addWarehouse.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/warehouseManage/editWarehouse.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	function selectRow(obj){
		$(obj).find('input:radio[name="operateWarehouse"]')[0].checked=true;
	}
	
	function toEditWarehouse(){
		var radio=$('input:radio[name="operateWarehouse"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的仓库！");
			return;
		}
		editWarehouse(radio.val());
	}
	
	function toDeleteWarehouse(){
		var radio=$('input:radio[name="operateWarehouse"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的仓库！");
			return;
		}
		confirmDeleteWarehouse(radio.val());
	}
		
	function confirmDeleteWarehouse(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>warehouse/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "warehousemanagementid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","仓库已删除！",Prompt.refresh);
					}else{
						Prompt.alert("删除提示","仓库删除失败！");
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该仓库吗?删除后无法恢复",delFunc);
	}
	</script>
</body>
</html>